// Generated with RobotBuilder version 0.0.1
package org.usfirst.frc2876.Robot2013.commands;

import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.command.Command;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import org.usfirst.frc2876.Robot2013.Robot;

/**
 *
 */
public class Shoot extends Command {

    boolean isdone;
    double startTime;

    public Shoot() {

        // Use requires() here to declare subsystem dependencies
        // eg. requires(chassis);

        // The following variables are automatically assigned by
        // robotbuilder and will be updated the next time you export to
        // Java from robot builder. Do not put any code or make any change
        // in the following block or it will be lost on an update. To
        // prevent this subsystem from being automatically updated, delete
        // the following line.
        // BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=REQUIRES
        requires(Robot.shooter);
        // END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=REQUIRES
    }
    // Called just before this Command runs the first time

    protected void initialize() {

        startTime = Timer.getFPGATimestamp();
        isdone = false;
        Robot.shooter.endFeeder();
        Robot.shooter.startShooter();

    }
    // Called repeatedly when this Command is scheduled to run
    int feeds = 0;

    protected void execute() {
        double now = Timer.getFPGATimestamp();
        double currentTime = now - startTime;
        SmartDashboard.putNumber("Timer", currentTime);

        if (currentTime >= 2) {
            Robot.shooter.startFeeder();
        }
        if (currentTime >= 8) {
            isdone = true;
        }
        SmartDashboard.putBoolean("isFeederOn", Robot.shooter.isFeederOn());
    }
    // Make this return true when this Command no longer needs to run execute()

    protected boolean isFinished() {
        return isdone;
    }
    // Called once after isFinished returns true

    protected void end() {
        // Don't turn the shooter off here. The feeder might be loading
        // a frisbee at the same time so we need to let shooter run.
        // Turn off shooter in ShooterIdle
        //Robot.shooter.endShooter();
        Robot.shooter.endFeeder();
        SmartDashboard.putBoolean("isFeederOn", Robot.shooter.isFeederOn());
    }
    // Called when another command which requires one or more of the same
    // subsystems is scheduled to run

    protected void interrupted() {
        end();
    }
}
